package com.geek.concurrence4work;

/**
 * @Author: lishuangqiang
 * @Date: 2021/11/28
 * @Description:
 */

public class SynchronizedMethod {

    private static volatile long res = 0;

    private synchronized void doSum() {
        res = Homework03.sum3();
        notify();
    }

    private synchronized long getRes() throws InterruptedException {
        if (res == 0) {
            wait();
        }
        return res;
    }


    public static void main(String[] args) throws InterruptedException {
        SynchronizedMethod synchronizedMethod = new SynchronizedMethod();
        Thread thread = new Thread(() -> {
            synchronizedMethod.doSum();
        });
        thread.start();
        System.out.println(synchronizedMethod.getRes());

    }
}
